package com.xuetang9.t9.xinhuaxia.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.xuetang9.t9.xinhuaxia.beans.Goods;
import com.xuetang9.t9.xinhuaxia.mappers.GoodsMapper;
import com.xuetang9.t9.xinhuaxia.service.IGoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author 李亚奇
 * @version 1.0
 * @desc TODO
 * @date 2020/2/23 17:11
 * @copyright liyq
 * @address 成都西部国际金融中心2栋2201
 **/
@Service
@Resource(name = "GoodsMapper")
public class GoodsService implements IGoodsService {
    @Autowired
    private GoodsMapper goodsMapper;
    @Override
    public boolean insertGoods(Goods goods) {
        return goodsMapper.insertSelective(goods)>0;
    }

    @Override
    public boolean removeGoods(Long goodsId) {
        return goodsMapper.deleteByPrimaryKey(goodsId)>0;
    }

    @Override
    public boolean updateGoods(Goods goods) {
        return goodsMapper.updateByPrimaryKeySelective(goods)>0;
    }

    @Override
    public Goods queryById(Long goodsId) {
        return goodsMapper.queryById(goodsId);
    }

    @Override
    public Goods queryByGoods(Goods goods) {
        return goodsMapper.selectOne(goods);
    }

    @Override
    public PageInfo<Goods> queryByPage(int currenPage, int perPageSize) {
        System.out.println(currenPage+";"+perPageSize);
        PageHelper.startPage(currenPage,perPageSize);
        PageHelper.orderBy("goodsId desc");

        List<Goods> goodsList = goodsMapper.queryAll();
        PageInfo<Goods> pageInfo = new PageInfo<>(goodsList);
        System.out.println(pageInfo);
        return pageInfo;
    }

    @Override
    public PageInfo<Goods> queryByLabel(String label,int currenPage, int perPageSize) {
        PageHelper.startPage(currenPage,perPageSize);
        PageHelper.orderBy("goodsId desc");
        List<Goods> goodsList = goodsMapper.queryByLable(label);
        PageInfo<Goods> pageInfo = new PageInfo<>(goodsList);
        System.out.println(pageInfo);
        return pageInfo;
    }

    @Override
    public List<Goods> queryShopMain(String Label) {
        return goodsMapper.queryByLable(Label);
    }

    @Override
    public List<Goods> queryAll() {
        return goodsMapper.queryAll();
    }

    @Override
    public List<Goods> queryByFirstCategory(Long fid) {
        return goodsMapper.queryAllByFirstCatgory(fid);
    }


}
